
*************************************************************************************************************************************;
* Code name: Part2_Edu_industry.sas
* Author: Thomas Jansson (Sveriges Riksbank)
* Latest update: June 19, 2023
* Goal: To estimate the concentration of specific education levels and majors in an industry. 
		Run it separately for the years of 1993 and 1999.
*************************************************************************************************************************************;

*Use key between old and new education classification systems;
data edukey;
	set original.WEB_SUN2000nyckelny;
		where C1 NE 'SUN  ';
		bsun = C1;
		rename C1 = utbildn C4 = bsuninr C3 = BSUNNIV;
		drop C2 C5 C6;
run;

proc sort data = edukey;
	by bsun;
run;

*************************************************************************************************************************************;
*Use data from original LINDA datasets from 1993 and 1999 (education, income, industry etc.);
data edu1999;
	set original.lindaf1999 (keep = nybidnr bsun bsunar bald BKUNGR bngr cprim csfvi cbefvi ctxfvi cdispl BURVKODF);
run;
			
data edu1993;
	set original.lindaf1993 (keep = nybidnr bsun bsunar bald BKUNGR cprim csfvi cdispl BURVKODF);
run;
	
proc sort data = edu1999;
	by bsun;
run;
	
proc sort data = edu1993;
	by bsun;
run;

*************************************************************************************************************************************;
*Create education level and major variables at different levels (1-, 2-, and 3-digit);
data temp.education1999;
	merge edukey edu1999(in = in_edu);
		by bsun;
			if in_edu = 1;

	edulevel_2 = substr(bsunniv,1,2);
	edumajor_2 = substr(bsuninr,1,2);
	edumajor_3 = substr(bsuninr,1,3);
	edulevel_1 = substr(bsunniv,1,1);
	edumajor_1 = substr(bsuninr,1,1);
	sni_2 = substr(bngr,1,2);
	sni_1 = substr(bngr,1,1);
	bransch_sni92 = input(BKUNGR,best5.);

	rename cprim = inc_earned csfvi = inc_broad cbefvi = inc_assessed ctxfvi = inc_taxable;
run;

data temp.education1993;
	merge edukey edu1993(in = in_edu);
		by bsun;
			if in_edu = 1;

	edulevel_2 = substr(bsunniv,1,2);
	edumajor_2 = substr(bsuninr,1,2);
	edumajor_3 = substr(bsuninr,1,3);
	edulevel_1 = substr(bsunniv,1,1);
	edumajor_1 = substr(bsuninr,1,1);
	sni_2 = substr(BKUNGR,1,2);
	sni_1 = substr(BKUNGR,1,1);
	bransch_sni92 = input(BKUNGR,best5.);

	rename cprim = inc_earned;
run;

*************************************************************************************************************************************;
*Frequency of different education majors (3-digit) in industries (2-digit) by education level (1-digit);
proc sort data = temp.education1999;
	by edulevel_1;
run;

proc sort data = temp.education1993;
	by edulevel_1;
run;

proc freq data = temp.education1999;
	table edumajor_3*sni_2 / out = temp.edu_ind_1999;
		by edulevel_1;
	where 25<bald<60 and inc_earned>50000 and burvkodf = 1; *consider only sampled individuals between 25 and 60 years of age with a minimum income of SEK 50,000;
run;

proc freq data = temp.education1993;
	table edumajor_3*sni_2 / out = temp.edu_ind_1993;
		by edulevel_1;
	where 25<bald<60 and inc_earned>500 and burvkodf = 1; *Note that income is defined in 100s of SEK in 1993;
run;

*************************************************************************************************************************************;
*Save education (orientation) data for 1999;
data temp.edu_orient1999;
	set temp.education1999;
		rename edumajor_3 = edumajor_3_99 edumajor_2 = edumajor_2_99 edumajor_1 = edumajor_1_99 nybidnr = id;
	keep edumajor_1 edumajor_2 edumajor_3 nybidnr;
run;

proc sort data = temp.edu_orient1999;
	by id;
run;

*************************************************************************************************************************************;
*Export to Excel (.csv) for import to Stata;
proc export data = temp.edu_ind_1999
		 outfile = "\\micro.intra\projekt\P0459$\P0459_gem\SAS DATA\Thomas\Projekt2\bal\edu3_SNI_1999_230423.csv" dbms=csv replace;
run;

proc export data = temp.edu_ind_1993
		 outfile = "\\micro.intra\projekt\P0459$\P0459_gem\SAS DATA\Thomas\Projekt2\bal\edu3_SNI_1993_230423.csv" dbms=csv replace;
run;
*************************************************************************************************************************************;




